package com.example.kemusan.service.impl;

import com.example.kemusan.mapper.SystemuserInfoMapper;
import com.example.kemusan.pojo.Result;
import com.example.kemusan.pojo.SystemuserInfo;
import com.example.kemusan.pojo.dto.NewPassword;
import com.example.kemusan.service.SystemuserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SystemuserInfoServiceImpl implements SystemuserInfoService {

    @Autowired
    private SystemuserInfoMapper systemuserInfoMapper;

    @Override
    public Result login(SystemuserInfo systemuserInfo) {
        SystemuserInfo user = systemuserInfoMapper.selectSystemuser(systemuserInfo);
        if (user != null)
            return Result.success("登录成功！");
        return Result.error("账号或密码错误！");
    }

    /**
     * 修改密码
     *
     * @param newPassword
     * @return
     */
    @Override
    public Result setNewPassword(NewPassword newPassword) {
        Integer count = systemuserInfoMapper.setNewPassword(newPassword);
        if (count == null || count == 0)
            return Result.error("账号或原密码错误！");
        return Result.success("修改成功！");
    }
}
